<?php
include("../class/classNoticia.php");
include("../class/classImage.php");
switch($show){
	case "noticiasInsert": noticiasInsert();break; 
	case "insert": insert();break;
}

function noticiasInsert(){
?>
<div class="form">
<form method="post" action="noticias.php?show=insert" enctype='multipart/form-data'>

	<label>
	<span>Fecha<small>(dd/mm/aaaa)</small>
	</span><input type="text" class="input-text" name="fecha_noticia" />
	</label>
	
	<label>
	<span>Titulo</span>
	<input type="text" class="input-text-big" name="titulo" />
	</label>
	
	<label>
	<span>Resumen</span>
	<textarea class="textarea-big" name="resumen"></textarea>
	</label>
	
	<label>
	<span>url Noticia</span>
	<input type="text" class="input-text" name="url" />
	</label>
	
	<label>
	<span>Autor</span>
	<select class="input-text" name="id_noticia_fuente">
	<option value="1">Defensor&iacute;a del Pueblo</option>
	<option value="2">Diario El Liberal</option>
	<option value="3">Diario Panorama</option>
	</select>
	</label>
		
	<label>
	<span>promovida</span>
	si:<input type="radio" class="radio" name="promovida" value="1" checked="checked" />, no:<input type="radio" name="promovida" value="0" />
	</label>
	
	<label>
	<span>imagen</span>
	<input type='file' name='imagen' />
	</label>
	
	<label>
	<span>Noticia</span>
	<textarea class="textarea-big" name="noticia"></textarea>
	</label>	
	<input type="hidden" name="insert" value="true" />
	<input type="submit" class="submit" value="cargar" name="cargar">
</form>
</div>
<?php 
}
?>

<?php
function insert(){
	if($_REQUEST["insert"]== "true"){
		$news = new classNoticia();
			$news->fecha_noticia = $_REQUEST["fecha_noticia"];
			$news->titulo=$_REQUEST["titulo"];
			$news->resumen=$_REQUEST["resumen"];
			$news->noticia=$_REQUEST["noticia"];
			$news->url=$_REQUEST["url"];
			$news->id_noticia_fuente=$_REQUEST["id_noticia_fuente"];
			$news->promovida=$_REQUEST["promovida"];
			$newsId = $news->insert();
		
			//subo la imagen
			$image = new classImage();
			$image->upload("../images/noticias/",$_FILES['imagen'], $newsId);
			echo "Noticia cargada correctamente";
	}
	else{
		echo "error";
	}
}
?>